exports.__esModule = true;

function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; }

/**
 * 行政区划控制器
 */
exports.default = class extends think.BaseController {
  areaListAction() {
    var _this = this;

    return _asyncToGenerator(function* () {
      const areaList = yield _this.service('sys/AreaService').getAreaList();
      return _this.successJson(areaList);
    })();
  }

  /**
     * 获取所有表单信息
     *
     * @returns
     */
  getAllAreaAction() {
    var _this2 = this;

    return _asyncToGenerator(function* () {
      const aj = think.ajaxJson();
      const AreaService = _this2.service('sys/AreaService');
      const res = yield AreaService.getAllArea();
      if (res && res.error) {
        aj.success = false;
        aj.msg = '获取失败';
      } else {
        aj.result = res;
      }
      return _this2.json(aj);
    })();
  }

  /**
     * 获取区域数据将areaCode设置为id
     */
  queryAreaByAreaCodeAction() {
    var _this3 = this;

    return _asyncToGenerator(function* () {
      const AreaService = _this3.service('sys/AreaService');
      const area_code = _this3.post('area_code');
      const res = yield AreaService.queryAreaByAreaCode(area_code);
      if (res && res.error) {
        return _this3.errorJson('查询失败');
      } else {
        return _this3.successJson(res);
      }
    })();
  }

  /**
     * 根据获取区域数据
     */
  queryAreaByIdAction() {
    var _this4 = this;

    return _asyncToGenerator(function* () {
      const AreaService = _this4.service('sys/AreaService');
      const area_code = _this4.post('id');
      const res = yield AreaService.queryAreaById(area_code);
      if (res && res.error) {
        return _this4.errorJson('查询失败');
      } else {
        return _this4.successJson(res);
      }
    })();
  }
};